﻿using Jmit.Deyi.Job;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Jmit.Deyi.AutoTask.DataSync
{
	public class JobStart
	{
		public void Start()
		{

            int downInterval = int.Parse(AppConfigManager.appConfig.down_minute);    // 下载轮询时间
            int upInterval = int.Parse(AppConfigManager.appConfig.up_minute);        // 上传轮询时间

            // 调用 StartJobWithSimple 方法
            if (Form1.isSelectedJob1)
            {
                //QuartzManage.DeleteJob("TestJob1");
                //QuartzManage.StartJobWithSimple<TestJob1>("TestJob1", schedule => schedule.WithIntervalInSeconds(downInterval).RepeatForever());//5秒钟一次

                // dps下载
                QuartzManage.DeleteJob("DPSJob_down");
                QuartzManage.StartJobWithSimple<DPSJob_down>("DPSJob_down", schedule => schedule.WithIntervalInMinutes(downInterval).RepeatForever());//1分钟一次
            }
            if (Form1.isSelectedJob2)
            {
                //QuartzManage.DeleteJob("TestJob2");
                //QuartzManage.StartJobWithSimple<TestJob2>("TestJob2", schedule => schedule.WithIntervalInSeconds(upInterval).RepeatForever());//5秒钟一次

                // dps上传
                QuartzManage.DeleteJob("DPSJob_up");
                QuartzManage.StartJobWithSimple<DPSJob_up>("DPSJob_up", schedule => schedule.WithIntervalInMinutes(upInterval).RepeatForever());//1分钟一次
            }



            // dps转储数据（保留一天数据）
            QuartzManage.DeleteJob("DPSJob_dump");
            QuartzManage.StartJobWithSimple<DPSJob_dump>("DPSJob_dump", schedule => schedule.WithIntervalInMinutes(30).RepeatForever());//30分钟一次

            //QuartzManage.StartJobWithSimple<TestJob2>("TestJob2", schedule => schedule.WithIntervalInMinutes(5).RepeatForever());//5秒钟一次

            //QuartzManage.StartJobWithCron<TestJob1>("TestJob1", "0/1 * * * * ?");//5秒钟一次
            //QuartzManage.StartJobWithCron<TestJob2>("TestJob2", "0 */" + minute + " * * * ?");//8秒钟一次

            //QuartzManage.StartJobWithCron<DPSJob_wmstodps>("DPSJob_wmstodps", "0 */" + minute + " * * * ?");//8秒钟一次
            //Console.ReadLine();
            LogHelpter.AddLog("-----启动任务----");
        }

        public void ReStart()
        {
            //string minute = AppConfigManager.appConfig.minute;
            //LogHelpter.AddLog("-----启动任务----");
            //QuartzManage.StartJobWithCron<TestJob1>("TestJob1", "0/1 * * * * ?");//5秒钟一次

            //QuartzManage.StartJob();
        }

        // 暂停
        public void Pause()
        {
            if (Form1.isSelectedJob1) QuartzManage.DeleteJob("TestJob1");
            //QuartzManage.DeleteJob("TestJob2");
            //QuartzManage.DeleteJob("DPSJob_wmstodps");


            LogHelpter.AddLog("-----关闭任务----");
            //QuartzManage.ShutDownJob(); // 一旦shutDown(),，就不能直接通过start()直接启动了，需要从新实例化Scheduler传出定时任务配置
            //QuartzManage.standbyScheduler();


        }

        public void Close()
        {

            LogHelpter.AddLog("-----关闭任务----");
            QuartzManage.ShutDownJob(); // 一旦shutDown(),，就不能直接通过start()直接启动了，需要从新实例化Scheduler传出定时任务配置
            //QuartzManage.standbyScheduler();


        }
    }
}
